Vanishing Points and Horizon
Select two pair of parallel lines
We can do that by selecting the edges of a square
cd ~/Documents/Polimi/IACV/
I = imread('images/floor_tiles_hq.jpeg');
figure(1), imshow(I); figure(1), hold on;
a = [ptsx(1); ptsy(1); 1];
b = [ptsx(2); ptsy(2); 1];
c = [ptsx(3); ptsy(3); 1];
d = [ptsx(4); ptsy(4); 1];
Let's now define the lines where the edges lie
Vanishing points
Horizon: line at infinity
Plot
figure(1), set(0, 'DefaultLineLineWidth', 2);
for p=[[a; b], [b; c], [c; d], [a; d]]
% show points at infinity
figure(2), imshow(I); figure(2), hold on;
set(0, 'DefaultLineLineWidth', 2);
w1 = homogeneous_to_cartesian(v1);
w2 = homogeneous_to_cartesian(v2);
text(w1(1), w1(2), " v1", 'Fontsize', 20);
text(w2(1), w2(2), " v2", 'Fontsize', 20);
hc = homogeneous_to_cartesian_line(h);
x_coord = [min(w1(1), w2(1)), max(w1(1), w2(1))];
y_coord = hc(1) * x_coord + hc(2);
A plane has one horizon
Draw another pair of lines and check that they meet at the line at the same horizon.
Select the pair of lines.
figure(1), imshow(I); figure(1), hold on;
e = [ptsx(1); ptsy(1); 1];
f = [ptsx(2); ptsy(2); 1];
g = [ptsx(3); ptsy(3); 1];
l = [ptsx(4); ptsy(4); 1];
Get the lines and find their intersection
Check if the point belongs to the line at infinity (it won't because of some imprecisions in the selection of the points)
y_coord = hc(1) * x_coord + hc(2);
text(v3(1)/v3(3), v3(2)/v3(3), " v3", 'Fontsize', 20);
function cart = homogeneous_to_cartesian(h) % for points
cart = [h(1)/h(3); h(2)/h(3)];
function cart = homogeneous_to_cartesian_line(h) % for lines
cart = [-h(1)/h(2); -h(3)/h(2)];
function segment(p, figure_number) % draws a segment. p=[q1; q2] where qi are the points in hom coord
p1 = homogeneous_to_cartesian(p(1:3));
p2 = homogeneous_to_cartesian(p(4:6));
figure(figure_number), plot([ p1(1), p2(1) ], [ p1(2), p2(2) ]);